﻿<%@ Page Title="" Language="C#" MasterPageFile="~/master/manager.master" AutoEventWireup="true"
    CodeBehind="user_list.aspx.cs" Inherits="RailwayReservationWeb.manager.user_list" %>

<asp:Content ID="Content2" ContentPlaceHolderID="PathContent" runat="server">
    <ol class="breadcrumb">
        <li><a href="default.aspx">Home</a></li>
        <li><a href="user_list.aspx">User</a></li>
        <li class="active"><a href="user_list.aspx">List</a></li>
    </ol>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <div class="page-header">
        <h1>
            Users List</h1>
    </div>
    <p id="pMessage" runat="server" class="alert alert-danger">
    </p>
    <div class="row">
        <div class="col-md-6">
            <div class="btn-group" style="margin-bottom: 15px">
                <asp:Button ID="btnShow" CssClass="btn btn-default" runat="server" Text="Show Deleted"
                    PostBackUrl="~/manager/user_list.aspx" CausesValidation="False" UseSubmitBehavior="False" />
            </div>
        </div>
        <div class="col-md-6">
            <div class="input-group">
                <asp:TextBox ID="txtSearch" CssClass="form-control" runat="server"></asp:TextBox>
                <span class="input-group-btn">
                    <asp:Button ID="btnSearch" CssClass="btn btn-default" runat="server" Text="Search"
                        OnClick="btnSearch_Click" />
                </span>
            </div>
        </div>
    </div>
    <asp:GridView ID="gvwUsers" runat="server" Width="100%" CssClass="table table-condensed table-bordered table-striped table-hover"
        AutoGenerateColumns="False" DataSourceID="ldsUsers" AllowPaging="True" AllowSorting="True"
        OnRowCommand="gvwUsers_RowCommand">
        <Columns>
            <asp:BoundField DataField="AccountId" HeaderText="Id" ReadOnly="True" SortExpression="AccountId" />
            <asp:BoundField DataField="FullName" HeaderText="Full Name" ReadOnly="True" SortExpression="FullName" />
            <asp:BoundField DataField="UserName" HeaderText="User Name" ReadOnly="True" SortExpression="UserName" />
            <asp:BoundField DataField="Email" HeaderText="Email" ReadOnly="True" SortExpression="Email" />
            <asp:TemplateField HeaderText="Role" SortExpression="Role">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# GetRoleName((Int16)Eval("Role")) %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Role") %>'></asp:TextBox>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField ShowHeader="False">
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandArgument='<%# Bind("AccountId") %>'
                        CommandName="AltEdit" Text="Edit" Enabled='<%# ((Int32)Eval("AccountId") != CurrentAccountId()) %>'></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandArgument='<%# Bind("AccountId") %>'
                        CommandName='<%# ((Int16)Eval("Status")==0)?"AltRestore":"AltDelete" %>' Text='<%# ((Int16)Eval("Status")==0)?"Unban":"Ban" %>'
                        Enabled='<%# ((Int32)Eval("AccountId") != CurrentAccountId()) %>'></asp:LinkButton>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
                        Text="Update"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                        Text="Cancel"></asp:LinkButton>
                </EditItemTemplate>
            </asp:TemplateField>
        </Columns>
        <PagerStyle CssClass="pagerArea" Wrap="True" />
        <PagerTemplate>
            <asp:GridPager ID="GridViewPager1" runat="server" ShowFirstAndLast="True" ShowNextAndPrevious="True"
                PageLinksToShow="10" NextText="&rsaquo;" PreviousText="&lsaquo;" FirstText="&laquo;"
                LastText="&raquo;" />
        </PagerTemplate>
        <EmptyDataTemplate>
            There are currently no items in this table.
        </EmptyDataTemplate>
    </asp:GridView>
    <asp:LinqDataSource ID="ldsUsers" runat="server" ContextTypeName="RailwayReservationWeb.RailwayReservationDataContext"
        EntityTypeName="" Select="new (AccountId, UserName, Email, FullName, Role, Status)"
        TableName="Accounts" EnableUpdate="True" Where="Status != @Status">
        <WhereParameters>
            <asp:QueryStringParameter DefaultValue="0" Name="Status" QueryStringField="s" Type="Int16" />
            <asp:QueryStringParameter DefaultValue="" Name="UserName" QueryStringField="q" Type="String" />
        </WhereParameters>
    </asp:LinqDataSource>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="SideContent" runat="server">
    <div class="panel panel-primary panel-navi">
        <!-- Default panel contents -->
        <div class="panel-heading">
            Manage Users</div>
        <!-- List group -->
        <ul class="list-group">
            <li class="list-group-item"><a href="user_list.aspx">View Users List</a></li>
            <li class="list-group-item"><a href="user_add.aspx">Add New User</a></li>
        </ul>
    </div>
</asp:Content>
